<!-- 搜索页面 -->
<template>

	<view class="page">
		<view class="con">
			<view class="uni-list" v-if="listData.length != 0">
				<view class="uni-list-cell" hover-class="uni-list-cell-hover" v-for="(item, index) in listData" :key="index" @click="goDetail(item, index)">
					<view class="uni-media-list">
						<text class="width-a100">{{item && item.title && item.title.value}}</text>
						<button class="width-auto upload-btn" v-show="item && item.isLoadData" @click.stop="uploadSampleData(item, index)">
							{{item.isLoadData === true ? '上传': item.isLoadData}}
						</button>
					</view>
				</view>
			</view>
		</view>
		<!-- <button type="primary" class="primary" @tap="goSpeech">语音识别</button> -->
	</view>

</template>

<script>
	import net from '../../net.js';
	import service from '../../service.js';
	import utils from '../../common/utils.js';
	import uploaddata from '../../uploaddata.js';

	export default {
		components: {},
		data() {
			return {
				listData: [],
				loadingType: 0,
				val: '',
			}
		},
		onNavigationBarButtonTap(obj) { //监听原生标题栏按钮点击事件，参数为Object
			console.log('点击搜索'+obj);	
			this.getList();
			
		},
		onNavigationBarSearchInputChanged(obj) { //监听原生标题栏搜索输入框输入内容变化事件
			this.val = '';
			this.val = obj.text;
			console.log("内容____" + obj.text)
		},
		onNavigationBarSearchInputConfirmed(e) { //监听原生标题栏搜索输入框搜索事件，用户点击软键盘上的“搜索”按钮时触发。
			console.log("软键盘搜索____" + e.text)
			this.getList();
		},

		methods: {
			//根据搜索栏的字段获取数据
			getList(val) {
				if(this.val.length != 0 && this.val!=this.val.match(/^\s+$/)){
					net.netGet(`/module/api/main/getTaskData?title=${this.val}`, {}, (res) => {
						console.log(res)
						if (res != null && Array.isArray(res) && res.length != 0) {
							this.listData = res;
							uni.showToast({
								icon: 'none',
								title: '正在搜索',
								duration: 500
							});	
							service.setTaskList(this.listData);
						} else {
							uni.showToast({
								icon: 'none',
								title: '搜索不到该任务名',
							});
							this.listData=[];
						}
					}, () => {
						uni.showToast({
							icon: 'none',
							title: '无法更新数据'
						});
					});
				}else{
					uni.showToast({
						icon: 'none',
						title: '请输入搜索内容',
					});
				}
					
				
				
			},
			//点击任务跳转到任务详情
			goDetail(data, index) {

				let param = utils.toParam({
					data: data,
					index: index
				});

				// 设置 更新首页数据的回调
				utils.setMainCallBack((res, isLoadData) => {
					data.isLoadData = isLoadData;
					service.setTaskIndex(data, index);
				});

				uni.redirectTo({
					url: "./detail" + param
				});

			},

		}

	}
</script>

<style>
	.page {
		width: 100%;
		padding-top: 20upx;
		height: auto;
	}

	page {
		background: #efeff4;
	}

	.uni-list-cell:after {
		left: 0;
	}

	.uni-media-list-body {
		height: auto;
		justify-content: space-around;
	}

	.upload-btn {
		font-size: 32upx;
		padding: 10upx 18upx;
		line-height: 14upx;
		margin: 0;
	}
</style>
